package com.cn.controller;

import com.cn.model.User;
import com.cn.validator.GetRegisterValidator;
import com.cn.validator.GetUserValidator;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

public class HomeController extends Controller{
	public void index()
	{
		render("main.jsp");
	}
	public void orders() {
		render("orders.jsp");
	}
	/**
	 * 判断用户登录
	 */
	@Before(GetUserValidator.class)
	public void getUser() {
		System.out.println("123");
//		setAttr("caozuo", false);
//		setAttr("message", "呵");
		String id = getPara("ID");
		setSessionAttr("user",id );
		renderJson();
	}
	/**
	 * 注册
	 */
	@Before(GetRegisterValidator.class)
	public void getRegister(){
//		System.out.println("456");
		User user = getModel(User.class,"user");
		user.save();
		setAttr("caozuo", true);
		setAttr("message", "/Shopping");
		renderJson();
	}
	/**
	 * 退出登录
	 */
	public void signOut() {
		if (getSessionAttr("user") != null) {
			removeSessionAttr("user");
		}
		index();
	}

}
